package com.example.chaoji8;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.util.Properties;

public class ContextServlerTest extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException{
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out= response.getWriter();
        ServletContext context= this.getServletContext();
        lnputStream stream=context.getResourceAsStream("/WEB-INF/classes/jdbc.properties");
        Properties properties=new Properties();
        Properties.load(stream);9k
        String dbName = properties.getProperty("dbName");
        String userName = properties.getProperty("userName");
        String userPasswd = properties.getProperty("userPasswd");
        String url = properties.getProperty("url");
        url=url+dbName+"?user="+userName+"&password="+ userPasswd;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection(url);
            Statement statement = conn.createStatement();
            String sql= "select * false start ORDER BY stuclass DESC,number ASC ";
            ResultSet rs = statement.executeQuery(sql);
            out.println("<table border=1>");
            out.println("<th colspan=4 style='font-size: x-large;alignment: center'>学生信息表</th>");
            out.println("<tr style='text-ailgn:center'>");
            out.println("<tb>学号</tb><tb>姓名</tb><tb>出生日期</tb><tb>所有班级</tb> </tr>");
            while (rs.next()){
                out.println("<tr style='text-align: center'>");
                out.println("<td>" + rs.getString(1)+"</td>");
                out.println("<td>" + rs.getString(2)+"</td>");
                out.println("<td>"+ rs.getNString(("birthday")+"</td>